home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / SOURCE.BIN / ToolBarSpacer.java < prev    next >
Encoding:
Java Source  |  1997-06-19  |  2.6 KB  |  92 lines

  1. package symantec.itools.awt.util;
  2.  
  3.  
  4. import java.awt.Canvas;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8.  
  9. //     01/29/97    TWB    Integrated changes from Macintosh
  10.  
  11. /**
  12.  * ToolBarPanelSpacer component.
  13.  * This component is used to space items in a ToolBarPanel.
  14.  * @see symantec.itools.awt.util.ToolBarPanel
  15.  * @version 1.0, Nov 26, 1996
  16.  * @author Symantec
  17.  */
  18.  
  19.  
  20. public class ToolBarSpacer
  21.     extends Canvas
  22. {
  23.     /**
  24.      * Create a ToolBarSpacer.
  25.      */
  26.     public ToolBarSpacer()
  27.     {
  28.     }
  29.  
  30.     /**
  31.      * Paints this component using the given graphics context.
  32.      * This is a standard Java AWT method which typically gets called
  33.      * by the AWT to handle painting this component. It paints this component
  34.      * using the given graphics context. The graphics context clipping region
  35.      * is set to the bounding rectangle of this component and its <0,0>
  36.      * coordinate is this component's top-left corner.
  37.      *
  38.      * Fills the spacer's area with the background color.
  39.      *
  40.      * @param g the graphics context used for painting
  41.      * @see java.awt.Component#repaint
  42.      * @see java.awt.Component#update
  43.      */
  44.     public void paint(Graphics g)
  45.     {
  46.         Dimension d = size();
  47.         g.clipRect(0, 0, d.width, d.height);
  48.         g.setColor(super.getBackground());
  49.         g.fillRect(0, 0, d.width, d.height);
  50.     }
  51.  
  52.     /**
  53.      * Returns the recommended dimensions to properly display this component.
  54.      * This is a standard Java AWT method which gets called to determine
  55.      * the recommended size of this component.
  56.      *
  57.      * @return  the width of this component and a height of tallest component the
  58.      *          ToolBarPanel.
  59.      *
  60.      * @see #minimumSize
  61.      */
  62.     public synchronized Dimension preferredSize()
  63.     {
  64.         Dimension s = this.size();// we want to retain user's width
  65.         s.height = 10;              // ... but constrain the height
  66.  
  67.         Component[] list = getParent().getComponents();
  68.  
  69.         for (int i = 0; i < list.length; ++i) {
  70.             Component c = list[i];
  71.             if (!(c instanceof ToolBarSpacer))
  72.                 s.height = Math.max(s.height, c.size().height);
  73.         }
  74.  
  75.         return s;
  76.     }
  77.     /**
  78.      * Returns the minimum dimensions to properly display this component.
  79.      * This is a standard Java AWT method which gets called to determine
  80.      * the minimum size of this component.
  81.      *
  82.      * In this case the minimum size is the same as the preferred size.
  83.      *
  84.      * @see #preferredSize
  85.      */
  86.     public synchronized Dimension minimumSize()
  87.     {
  88.         return preferredSize();
  89.     }
  90. }
  91.  
  92.